package com.ktjy.service;

import com.ktjy.entity.SysUser;
import com.ktjy.mapper.SysUserMapper;

import java.util.List;

public class SysUserServiceImpl implements SysUserService {
    // 定义 Mapper
    private SysUserMapper sysUserMapper;
    // 提供 setter 方法用于注入属性
         public void setSysUserMapper(SysUserMapper sysUserMapper) {
            this.sysUserMapper = sysUserMapper;
         }
     @Override
     public List<SysUser> getSysUserList(SysUser sysUser) {
     return sysUserMapper.getSysUserList(sysUser);
      }

    @Override
    public int saveBatch(List<SysUser> sysUserList) {
        int rows = 0;
        for (int i = 0; i < sysUserList.size(); i++) {
        // 拿出每一条用户数据插入
        SysUser sysUser = sysUserList.get(i);
        if (i == 1) {
        // 插入第二条数据时，模拟数据库异常，查看事务是否生效
            throw new RuntimeException("数据库异常");
         }
        // 调用插入数据操作，计入总受影响行数
        rows += sysUserMapper.insert(sysUser);
    }
    // 返回总受影响行数
    return rows;
    }
//    @Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,
//             readOnly=false,timeout=-1)
//    public class SysUserServiceImpl implements SysUserService {
// // ...省略业务代码
//
//         @Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,
//                readOnly=false,timeout=-1)
//@Override
//public int saveBatch(List<SysUser> sysUserList) {
//             return 0;
//         }
//    }
}
